package com.rbac.admin.config;

import com.rbac.admin.utils.SnowflakeIdGenerator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 雪花算法配置类
 * 
 * @author RBAC-Admin
 * @since 2024-01-01
 */
@Slf4j
@Configuration
@ConfigurationProperties(prefix = "snowflake")
public class SnowflakeConfig {

    /**
     * 机器ID (0-31)
     */
    private long workerId = 1L;

    /**
     * 数据中心ID (0-31)
     */
    private long datacenterId = 1L;

    @Bean
    public SnowflakeIdGenerator snowflakeIdGenerator() {
        log.info("Initializing SnowflakeIdGenerator with workerId: {}, datacenterId: {}", 
                workerId, datacenterId);
        return new SnowflakeIdGenerator(workerId, datacenterId);
    }

    public long getWorkerId() {
        return workerId;
    }

    public void setWorkerId(long workerId) {
        this.workerId = workerId;
    }

    public long getDatacenterId() {
        return datacenterId;
    }

    public void setDatacenterId(long datacenterId) {
        this.datacenterId = datacenterId;
    }
} 